#include "userlib.h"

static void stoptraceme(void)
{
	FILE *f;
	f = fopen("/proc/linalter", "w");
	if(f){
		fprintf(f, "a0");
		fclose(f);
	}else
		die("/proc/linalter");
}

void traceme(void)
{
	FILE *f;
	int i;
	f = fopen("/proc/linalter", "w");
	if(f==0){
		printf("no file /proc/linalter.\nPlease run '/etc/init.d/linalter' as root.\n");
		exit(0);
	}
	fprintf(f, "a1");
	fclose(f);
	f = fopen("/proc/linalter", "r");
	if(f==0)
		die("/proc/linalter");
	fscanf(f, "%d", &i);
	fclose(f);
	if(i!=1){
		fprintf(stderr, "I cannot be altered.\n");
		exit(1);
	}
	atexit(stoptraceme);
}

